package com.lifeng.patterns.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: lifeng
 * @create: 2020/9/22 15:10
 * 每个Bean的生成前后做一些逻辑操作
 * bean在调用构造之后，初始化方法前后进行一些操作
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        //TODO 可以做一下个性化属性设置
        System.out.println("bean 初始化前执行。。。:"+beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        //TODO 可以做一下个性化属性设置
        System.out.println("bean 初始化后执行。。。:"+beanName);
        return bean;
    }
}
